import dayjs from 'dayjs';
/**
 * 计算年龄，兼容字符串和 Date 对象
 */
export function calculateAge(birthday: string): number {
    if (!birthday) return 0;

    const birthDate = dayjs(birthday);
    const today = dayjs();

    let age = today.year() - birthDate.year();

    // 如果今年的生日还没到，则减一岁
    if (today.month() < birthDate.month() || 
        (today.month() === birthDate.month() && today.date() < birthDate.date())) {
        age--;
    }

    return age;
}